<?php
namespace app\admin\controller;


use think\Controller;
use app\admin\model\Login as log;
//use think\Request;
use think\Session;

class Login extends Controller
{
    private $model;
    public function __construct()
    {
        $this->model = new log();
    }

    public function login()
    {
        return view('login/login');

    }

    public function toLogin()
    {
//        return "111";die;
        $name = isset($_POST['user']) ? $_POST['user'] : '';
        $pwd = isset($_POST['pwd']) ? $_POST['pwd'] : '';
//        return $pwd;die;

        $result = $this->model->login($name, $pwd);
        if ($result) {
            Session::set('name', $name);
            $msg = '登录成功';
            return json_encode($msg);
        } else {
            $msg = '登录失败，错误的用户名和密码';
            return json_encode($msg);
        }

    }

    public function getLogin()
    {
        $name = Session::get('name');
        return json_encode($name);


    }

    public function deLogin()
    {
        Session::delete('name');
        $name =0;
        return json_encode($name);
    }



}
